<template>
	<view>
		<!-- 搜索框 -->
		<view class="search_view">
			<u-search
				shape="square"
				:show-action="true" 
				action-text="搜索" 
				:clearabled="true"  
				:animation="true" 
				v-model="keywords"
				@search="search"
				@custom="search"
				@clear="clear">
			</u-search>
		</view>
		<view class="list" v-if="buffer">
			<view class="row" v-for="(item, index) in list" @click="goDetails(item)">
				<image :src="item.img" mode="widthFix"></image>
				<view class="info">
					<text>{{item.goodsname}}</text>	
					<text>￥{{item.price}}</text>	
					<text>{{item.market_price}}评论</text>	 
				</view>
			</view>
		</view>
		<view class="api" v-else>
			没有数据亲！
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				buffer:true,//页面显示开关,
				keywords:'',//初始化搜索关键词
				list: [],
			}
		},
		onLoad(options){
			this.request_search();
		},
	
		methods: {
			search(value){
				console.log(value);
				uni.redirectTo({
					url: `/pages/search/search?value=${value}`
				})
			},
			clear(){},
			
			goDetails(value){
				console.log(value);
				uni.navigateTo({
					url: `/pages/gooddesc/gooddesc?value=${JSON.stringify(value)}`
				})
			},
			
			async request_search(){
				let keywords = this.$mp.query.value;
				console.log(keywords);
				let [err, {data}] = await uni.request({
					url: `${this.$baseApi}search`,
					data: {keywords}
				});
				console.log(data);
				if(!data.list){
					this.list = [];
					this.buffer = false;
					return;
				}
				data.list.forEach(item => item.img = this.$baseUrl + item.img);
				this.list = data.list;
			}
		},
		
	}
</script>

<style>
	/* 引入样式 */
	@import url("@/static/css/search.css");
</style>
